VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMain 
   AutoRedraw      =   -1  'True
   Caption         =   "Blobber 2.0 ...cause it sounds better than 1.0"
   ClientHeight    =   4995
   ClientLeft      =   5190
   ClientTop       =   5850
   ClientWidth     =   8085
   Icon            =   "frmMain.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   4995
   ScaleWidth      =   8085
   Begin MSComctlLib.ProgressBar pgBar 
      Height          =   255
      Left            =   840
      TabIndex        =   10
      Top             =   4320
      Width           =   6615
      _ExtentX        =   11668
      _ExtentY        =   450
      _Version        =   393216
      Appearance      =   1
   End
   Begin VB.CommandButton cmdEdit 
      Caption         =   "&Edit"
      Enabled         =   0   'False
      Height          =   375
      Left            =   6480
      TabIndex        =   9
      Top             =   3750
      Width           =   1335
   End
   Begin VB.ListBox lstDuplicates 
      Height          =   3180
      Left            =   4200
      MultiSelect     =   2  'Extended
      Sorted          =   -1  'True
      TabIndex        =   7
      Top             =   360
      Width           =   3735
   End
   Begin VB.CommandButton cmdLoadBatchForm 
      Caption         =   "&Load Batch Files"
      Height          =   375
      Left            =   4920
      TabIndex        =   6
      Top             =   3750
      Width           =   1335
   End
   Begin VB.ListBox lstFullFiles 
      Height          =   3180
      ItemData        =   "frmMain.frx":0ECA
      Left            =   240
      List            =   "frmMain.frx":0ECC
      MultiSelect     =   2  'Extended
      Sorted          =   -1  'True
      TabIndex        =   5
      ToolTipText     =   "Double click on these to preview"
      Top             =   360
      Width           =   3735
   End
   Begin MSComDlg.CommonDialog cdBrowse 
      Left            =   -120
      Top             =   3240
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton cmdRemove 
      Caption         =   "&Remove File"
      Enabled         =   0   'False
      Height          =   375
      Left            =   1800
      TabIndex        =   2
      ToolTipText     =   "Remove selected files"
      Top             =   3750
      Width           =   1335
   End
   Begin VB.CommandButton cmdLoad 
      Caption         =   "&Browse for Files"
      Height          =   375
      Left            =   240
      TabIndex        =   1
      ToolTipText     =   "Add individual files"
      Top             =   3750
      Width           =   1335
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "&Add Images"
      Enabled         =   0   'False
      Height          =   375
      Left            =   3360
      TabIndex        =   0
      ToolTipText     =   "Add to database"
      Top             =   3750
      Width           =   1335
   End
   Begin VB.Label lblDuplicates 
      AutoSize        =   -1  'True
      Caption         =   "List of duplicates"
      Height          =   195
      Left            =   4200
      TabIndex        =   8
      Top             =   120
      Width           =   1185
   End
   Begin VB.Label lblList 
      AutoSize        =   -1  'True
      Caption         =   "Double click file to preview"
      Height          =   195
      Left            =   240
      TabIndex        =   4
      Top             =   120
      Width           =   1905
   End
   Begin VB.Label lblStatus 
      AutoSize        =   -1  'True
      Caption         =   "Sample Text"
      Height          =   195
      Left            =   120
      TabIndex        =   3
      Top             =   4680
      Width           =   885
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim mstream As ADODB.Stream

Public Filename As String
Public FullFileName As String
Public Extension As String


Public listCount As Integer
Public listCountDown As Integer
Public Sub AddToSql()


On Error GoTo ErrorLogger


listCountDown = listCountDown - 1
Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;data Source=INSERT SERVER NAME;Initial Catalog=INSERT DATABASE NAME;User Id=INSER USERID;Password=INSERT PASSWORD"

Set rs = New ADODB.Recordset
rs.Open "Select * from images2", cn, adOpenKeyset, adLockOptimistic

Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.LoadFromFile FullFileName



rs.AddNew
lblStatus.Caption = "Copying file: " & Filename & " --- " & listCountDown & " files left to copy"
pgBar.Value = 50
rs.Fields("name").Value = LCase(Filename) & LCase(Extension)


rs.Fields("extension").Value = LCase(Extension)

rs.Fields("content").Value = mstream.Read

rs.Update

rs.Close
cn.Close
mstream.Flush
'****************************************************'
ErrorLogger:
Select Case Err.Number
    Case 6:
        MsgBox "Overflow!"
    Case 13:
        MsgBox "Type Mismatch"
    Case -2147217873:
        'MsgBox "SQL Duplicate Insert Error" & Err.Description
        'lstDuplicates.AddItem LCase(Filename) & LCase(Extension)
        lstDuplicates.AddItem LCase(FullFileName)
        lblDuplicates.Caption = "Already in database"
        lstDuplicates.ToolTipText = "These were already in the database and where not added"
  
End Select
'****************************************************'
End Sub


Public Sub EditSQL()
On Error GoTo ErrorLogger
FullFileName = lstDuplicates.Text
pgBar.Value = 0
'listCountDown = listCountDown - 1
Call PrepareForSql 'does editing for extension, filename, and path
Set cn = New ADODB.Connection
'cn.Open "Provider=SQLOLEDB;data Source=INSERT SERVER NAME;Initial Catalog=INSERT DATABASE NAME;User Id=INSER USERID;Password=INSERT PASSWORD"

Set rs = New ADODB.Recordset
rs.Open "Select * from images2 WHERE name='" & Filename & Extension & "'", cn, adOpenKeyset, adLockOptimistic
rs.Delete
rs.Update
rs.Close

'only writing to the first record spot, overwriting what is there...fuck
rs.Open "Select * from images2", cn, adOpenKeyset, adLockOptimistic

Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.LoadFromFile FullFileName

rs.AddNew

pgBar.Value = 25

'lblStatus.Caption = "Copying file: " & Filename & " --- " & listCountDown & " files left to copy"
pgBar.Value = 50
rs.Fields("name").Value = LCase(Filename) & LCase(Extension)


rs.Fields("extension").Value = LCase(Extension)
pgBar.Value = 75
rs.Fields("content").Value = mstream.Read
lstDuplicates.RemoveItem (lstDuplicates.ListIndex)
rs.Update
pgBar.Value = 100
rs.Close
cn.Close
mstream.Flush
'****************************************************'
ErrorLogger:
Select Case Err.Number
    Case 6:
        MsgBox "Overflow!"
    Case 13:
        MsgBox "Type Mismatch"
    Case -2147217873:
        'MsgBox "SQL Duplicate Insert Error" & Err.Description
        'lstDuplicates.AddItem LCase(Filename) & LCase(Extension)
        lstDuplicates.AddItem LCase(FullFileName)
        lblDuplicates.Caption = "Already in database"
        lstDuplicates.ToolTipText = "These were already in the database and where not added"
  
End Select
'****************************************************'
End Sub

Private Function GetItemText(counter As Integer) As String
    
GetItemText = lstFullFiles.List(counter)
End Function
Private Sub AddFilter(ByVal dlg As CommonDialog, ByVal _
    filter_title As String, ByVal filter_value As String)
Dim txt As String

    txt = dlg.Filter
    If Len(txt) > 0 Then txt = txt & "|"
    txt = txt & filter_title & " (" & filter_value & ")|" & _
        filter_value
    dlg.Filter = txt
End Sub
Public Sub PrepareForSql()

Dim DotPosition As Integer 'Used to split extenstion and file description
Dim x As Integer 'used to count after period
Dim y As Integer 'used to count after period
Dim z As Integer


'strips out extension and path and leaves just the filename

Filename = Mid(FullFileName, (InStrRev(FullFileName, "\") + 1), (InStrRev(FullFileName, ".") - (InStrRev(FullFileName, "\") + 1)))

'counters
x = InStrRev(FullFileName, ".")
y = InStrRev(FullFileName, "\")

'where is the dot in the extension?
DotPosition = InStrRev(FullFileName, ".")

'heres the extension
Extension = Mid(FullFileName, DotPosition, x)

End Sub

Public Sub RemoveFromList()
Dim i As Integer
i = 0
While (i < lstFullFiles.listCount)
lstFullFiles.RemoveItem (i)
Wend
End Sub


Private Sub cmdAdd_Click()
MsgBox ("Program may appear to hang...just go with it.")

If (lstDuplicates.listCount > 0) Then lstDuplicates.Clear

Dim i As Integer 'counter
i = 0

listCount = lstFullFiles.listCount
listCountDown = listCount

pgBar.Visible = True
pgBar.Value = 0
pgBar.Max = listCount

While (i < listCount)
FullFileName = GetItemText(i)

Call PrepareForSql 'does editing for extension, filename, and path
Call AddToSql 'actual calls to database


i = i + 1
pgBar.Value = i
Wend

lblStatus.Caption = "Done!"
pgBar.Visible = False
pgBar.Value = 0
Call RemoveFromList
End Sub


Private Sub cmdEdit_Click()
'FullFileName = lstDuplicates.Text
Call EditSQL
lblDuplicates.Caption = "File " & Filename & Extension & " updated"
cmdEdit.Enabled = False
End Sub

Private Sub cmdLoad_Click()

'gets the file
cdBrowse.ShowOpen
FullFileName = cdBrowse.Filename


'testing input
If FullFileName = "" Then
Else
lstFullFiles.AddItem (FullFileName)
End If

lblStatus.Caption = "Files loaded: " & lstFullFiles.listCount
If lstFullFiles.listCount = 0 Then
cmdRemove.Enabled = False
cmdAdd.Enabled = False
Else
cmdRemove.Enabled = True
cmdAdd.Enabled = True
End If
End Sub


Private Sub cmdLoadBatchForm_Click()
frmBatch.Show (1)
End Sub

Private Sub cmdRemove_Click()

Dim placeholder As Integer

If lstFullFiles.ListIndex = -1 Then Exit Sub

lblDuplicates.Caption = "Files Removed"
lstDuplicates.ToolTipText = "These files will not be added to database"

If lblDuplicates.Caption = "Already in database" Then
    lblDuplicates.Caption = "Files Removed"
    lstDuplicates.ToolTipText = "These files will not be added to database"
    lstDuplicates.Clear
End If

    For placeholder = lstFullFiles.listCount - 1 To 0 Step -1
        If lstFullFiles.Selected(placeholder) = True Then
        
        lstDuplicates.AddItem lstFullFiles.List(placeholder)
        lstFullFiles.RemoveItem placeholder
        
    End If
    Next placeholder

lblStatus.Caption = "New file count: " & lstFullFiles.listCount


If lstFullFiles.listCount = 0 Then
    cmdRemove.Enabled = False
    cmdAdd.Enabled = False
Else
    cmdAdd.Enabled = True
End If

cmdRemove.Enabled = False
End Sub

Private Sub Form_Load()

lblStatus.Caption = ""
cdBrowse.Filter = ""
AddFilter cdBrowse, "Graphic Files", "*.bmp;*.gif;*.jpg;*.tif"

filecounter = 0
    
    

    
    
    
    
End Sub


Private Sub lstDuplicates_Click()
cmdEdit.Enabled = True
FullFileName = lstDuplicates.Text
End Sub

Private Sub lstDuplicates_DblClick()
ShellEx (lstDuplicates.Text)
End Sub


Private Sub lstFullFiles_Click()
cmdRemove.Enabled = True
End Sub

Private Sub lstFullFiles_DblClick()
ShellEx (lstFullFiles.Text)
End Sub


